#ifndef KBD_H
#define KBD_H

#include "irq.h"
#include "types.h"

//about data read/write
#define KBD_PORT_DATA 0x60
//status,read only
#define KBD_PORT_STAT 0x64
//command, write only
#define KBD_PORT_CMD  0x64

#define  KBD_STAT_OUT_READY   (1<<0)
#define  KBD_STAT_RECV_READY  (1<<1)
#define  KBD_STAT_TIME_OUT    (1<<6)
#define  KBD_STAT_PARITY_ERR  (1<<7)

#define KEY_E0  0xE0
#define KEY_E1  0xE1

#define KEY_RSHIFT 0x36
#define KEY_LSHIFT 0x2a
#define KEY_CAPS   0x3a
#define KEY_ALT   0x38
#define KEY_CTRL  0x1D

#define KEY_F1     0x3B
#define KEY_F2     0x3C
#define KEY_F3     0x3D
#define KEY_F4     0x3E
#define KEY_F5     0x3F
#define KEY_F6     0x40
#define KEY_F7     0x41
#define KEY_F8     0x42
#define KEY_F9     0x43
#define KEY_F10    0x44
#define KEY_F11    0x57
#define KEY_F12    0x58

#define KEY_ENTER 0x1C

#define KEY_LEFT   0x4B
#define KEY_RIGHT  0x4D
#define KEY_UP     0x48
#define KEY_DOWN   0x50   

#define KEY_BACK_SPACE 0x7f


typedef struct _key_map_t{
    uint8_t normal;
    uint8_t func;
}key_map_t;

typedef struct _kbd_state_t{
    int caps_lock :1;
    int lshift_press :1;
    int rshift_press:1;
    int lalt_press:1;
    int ralt_press:1;
    int lctrl_press:1;
    int rctrl_press:1;
}kbd_state_t;

void kbd_init(void);
void do_handler_kbd(exception_frame_t * frame);

void exception_handler_kbd(void);
#endif